﻿using System;
using UnityEngine;
using UnityEngine.EventSystems;

/// <summary>
/// 触发接听器
/// </summary>
public class EventTriggerListener : MonoBehaviour, IPointerClickHandler, IPointerDownHandler, IPointerEnterHandler,
IPointerExitHandler, IPointerUpHandler, IBeginDragHandler, IEndDragHandler, IDragHandler, IScrollHandler, IDropHandler, IMoveHandler, ISelectHandler, IDeselectHandler, IUpdateSelectedHandler, ISubmitHandler, ICancelHandler
{
    /// <summary>
    /// 触发接听方法委托
    /// </summary>
    /// <param name="go"></param>
    public delegate void VoidDelegate(GameObject go, BaseEventData data);
    /// <summary>
    /// 触发接听方法泛型委托
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="go"></param>
    /// <param name="param"></param>
    public delegate void VoidDelegate<T>(GameObject go, T param);
    /// <summary>
    /// 左击鼠标委托
    /// </summary>
    public VoidDelegate onClickLeft;
    /// <summary>
    /// 右击鼠标委托
    /// </summary>
    public VoidDelegate onClickRight;
    /// <summary>
    /// 中击鼠标委托
    /// </summary>
    public VoidDelegate onClickMiddle;
    /// <summary>
    /// 左按鼠标委托
    /// </summary>
    public VoidDelegate onDownLeft;
    /// <summary>
    /// 右按鼠标委托
    /// </summary>
    public VoidDelegate onDownRight;
    /// <summary>
    /// 中按鼠标委托
    /// </summary>
    public VoidDelegate onDownMiddle;
    /// <summary>
    /// 左抬鼠标委托
    /// </summary>
    public VoidDelegate onUpLeft;
    /// <summary>
    /// 右抬鼠标委托
    /// </summary>
    public VoidDelegate onUpRight;
    /// <summary>
    /// 左按压鼠标委托
    /// </summary>
    public VoidDelegate<float> onPressLeft;
    /// <summary>
    /// 中按压鼠标委托
    /// </summary>
    public VoidDelegate<float> onPressMiddle;
    /// <summary>
    /// 右按压鼠标委托
    /// </summary>
    public VoidDelegate<float> onPressRight;
    /// <summary>
    /// 中抬鼠标委托
    /// </summary>
    public VoidDelegate onUpMiddle;
    /// <summary>
    /// 左双击鼠标委托
    /// </summary>
    public VoidDelegate onDoubleClickLeft;
    /// <summary>
    /// 右双击鼠标委托
    /// </summary>
    public VoidDelegate onDoubleClickRight;
    /// <summary>
    /// 中双击鼠标委托
    /// </summary>
    public VoidDelegate onDoubleClickMiddle;
    /// <summary>
    /// 鼠标进入委托
    /// </summary>
    public VoidDelegate onEnter;
    /// <summary>
    /// 鼠标离开委托
    /// </summary>
    public VoidDelegate onExit;
    /// <summary>
    /// 鼠标悬浮委托
    /// </summary>
    public VoidDelegate onHover;
    /// <summary>
    /// 鼠标不悬浮委托
    /// </summary>
    public VoidDelegate onLeave;
    /// <summary>
    /// 开始拖拽委托
    /// </summary>
    public VoidDelegate onBeginDragLeft;
    /// <summary>
    /// 
    /// </summary>
    public VoidDelegate onBeginDragRight;
    /// <summary>
    /// 
    /// </summary>
    public VoidDelegate onBeginDragMiddle;
    /// <summary>
    /// 结束拖拽委托
    /// </summary>
    public VoidDelegate onEndDragLeft;
    /// <summary>
    /// 
    /// </summary>
    public VoidDelegate onEndDragRight;
    /// <summary>
    /// 
    /// </summary>
    public VoidDelegate onEndDragMiddle;
    /// <summary>
    /// 左拖拽委托
    /// </summary>
    public VoidDelegate onDragLeft;
    /// <summary>
    /// 右拖拽委托
    /// </summary>
    public VoidDelegate onDragRight;
    /// <summary>
    /// 中拖拽委托
    /// </summary>
    public VoidDelegate onDragMiddle;
    /// <summary>
    /// 鼠标滚轮委托
    /// </summary>
    public VoidDelegate onScroll;
    /// <summary>
    /// 
    /// </summary>
    public VoidDelegate onDrop;
    /// <summary>
    /// 
    /// </summary>
    public VoidDelegate onMove;
    /// <summary>
    /// 
    /// </summary>
    public VoidDelegate onSelect;
    /// <summary>
    /// 
    /// </summary>
    public VoidDelegate onDeselect;
    /// <summary>
    /// 
    /// </summary>
    public VoidDelegate onUpdateselect;
    /// <summary>
    /// 
    /// </summary>
    public VoidDelegate onSumit;
    /// <summary>
    /// 
    /// </summary>
    public VoidDelegate onCancel;
    /// <summary>
    /// 双击间隔
    /// </summary>
    public static float doubleClickTime = 0.3f;
    float clickTime = 0;
    float pressTime = 0;
    bool isHover = false;
    bool isPress = false;

    void Update()
    {
        if (!isHover)
        {
            onLeave?.Invoke(gameObject, null);
        }
        else
        {
            onHover?.Invoke(gameObject, null);
        }

        if (isPress)
        {
            pressTime += Time.deltaTime;
        }
    }

    void Start()
    {
        if (!Camera.main.GetComponent<PhysicsRaycaster>())
        {
            Camera.main.gameObject.AddComponent<PhysicsRaycaster>();
        }
        if (!FindObjectOfType<EventSystem>())
        {
            GameObject s = new GameObject("EventSystem");
            s.AddComponent<EventSystem>();
            s.AddComponent<StandaloneInputModule>();
        }
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="go"></param>
    /// <returns></returns>
    public static EventTriggerListener Get(GameObject go)
    {
        EventTriggerListener listener = go.GetComponent<EventTriggerListener>();
        if (listener == null) listener = go.AddComponent<EventTriggerListener>();
        return listener;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="eventData"></param>
    public void OnPointerClick(PointerEventData eventData)
    {
        EventSystem.current.SetSelectedGameObject(gameObject);
        switch (eventData.button)
        {
            case PointerEventData.InputButton.Left:
                onClickLeft?.Invoke(gameObject, eventData);
                break;
            case PointerEventData.InputButton.Right:
                onClickRight?.Invoke(gameObject, eventData);
                break;
            case PointerEventData.InputButton.Middle:
                onClickMiddle?.Invoke(gameObject, eventData);
                break;
            default:
                break;
        }
        if (Time.time - clickTime < doubleClickTime)
            switch (eventData.button)
            {
                case PointerEventData.InputButton.Left:
                    onDoubleClickLeft?.Invoke(gameObject, eventData);
                    break;
                case PointerEventData.InputButton.Right:
                    onDoubleClickRight?.Invoke(gameObject, eventData);
                    break;
                case PointerEventData.InputButton.Middle:
                    onDoubleClickMiddle?.Invoke(gameObject, eventData);
                    break;
                default:
                    break;
            }
        clickTime = Time.time;
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="eventData"></param>
    public void OnPointerDown(PointerEventData eventData)
    {
        isPress = true;
        pressTime = 0;
        switch (eventData.button)
        {
            case PointerEventData.InputButton.Left:
                onDownLeft?.Invoke(gameObject, eventData);
                break;
            case PointerEventData.InputButton.Right:
                onDownRight?.Invoke(gameObject, eventData);
                break;
            case PointerEventData.InputButton.Middle:
                onDownMiddle?.Invoke(gameObject, eventData);
                break;
            default:
                break;
        }
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="eventData"></param>
    public void OnPointerUp(PointerEventData eventData)
    {
        switch (eventData.button)
        {
            case PointerEventData.InputButton.Left:
                onUpLeft?.Invoke(gameObject, eventData);
                break;
            case PointerEventData.InputButton.Right:
                onUpRight?.Invoke(gameObject, eventData);
                break;
            case PointerEventData.InputButton.Middle:
                onUpMiddle?.Invoke(gameObject, eventData);
                break;
            default:
                break;
        }

        switch (eventData.button)
        {
            case PointerEventData.InputButton.Left:
                onPressLeft?.Invoke(gameObject, pressTime);
                break;
            case PointerEventData.InputButton.Right:
                onPressMiddle?.Invoke(gameObject, pressTime);
                break;
            case PointerEventData.InputButton.Middle:
                onPressRight?.Invoke(gameObject, pressTime);
                break;
            default:
                break;
        }
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="eventData"></param>
    public void OnPointerEnter(PointerEventData eventData)
    {
        onEnter?.Invoke(gameObject, eventData);
        isHover = true;

    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="eventData"></param>
    public void OnPointerExit(PointerEventData eventData)
    {
        onExit?.Invoke(gameObject, eventData);
        isHover = false;
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="eventData"></param>
    public void OnBeginDrag(PointerEventData eventData)
    {
        switch (eventData.button)
        {
            case PointerEventData.InputButton.Left:
                onBeginDragLeft?.Invoke(gameObject, eventData);
                break;
            case PointerEventData.InputButton.Right:
                onBeginDragRight?.Invoke(gameObject, eventData);
                break;
            case PointerEventData.InputButton.Middle:
                onBeginDragMiddle?.Invoke(gameObject, eventData);
                break;
            default:
                break;
        }
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="eventData"></param>
    public void OnEndDrag(PointerEventData eventData)
    {
        switch (eventData.button)
        {
            case PointerEventData.InputButton.Left:
                onEndDragLeft?.Invoke(gameObject, eventData);
                break;
            case PointerEventData.InputButton.Right:
                onEndDragRight?.Invoke(gameObject, eventData);
                break;
            case PointerEventData.InputButton.Middle:
                onEndDragMiddle?.Invoke(gameObject, eventData);
                break;
            default:
                break;
        }
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="eventData"></param>
    public void OnDrag(PointerEventData eventData)
    {
        switch (eventData.button)
        {
            case PointerEventData.InputButton.Left:
                onDragLeft?.Invoke(gameObject, eventData);
                break;
            case PointerEventData.InputButton.Right:
                onDragRight?.Invoke(gameObject, eventData);
                break;
            case PointerEventData.InputButton.Middle:
                onDragMiddle?.Invoke(gameObject, eventData);
                break;
            default:
                break;
        }
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="eventData"></param>
    public void OnScroll(PointerEventData eventData)
    {
        onScroll?.Invoke(gameObject, eventData);
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="eventData"></param>
    public void OnDrop(PointerEventData eventData)
    {
        onDrop?.Invoke(gameObject, eventData);
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="eventData"></param>
    public void OnMove(AxisEventData eventData)
    {
        onMove?.Invoke(gameObject, eventData);
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="eventData"></param>
    public void OnSelect(BaseEventData eventData)
    {
        onSelect?.Invoke(gameObject, eventData);
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="eventData"></param>
    public void OnDeselect(BaseEventData eventData)
    {
        onDeselect?.Invoke(gameObject, eventData);
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="eventData"></param>
    public void OnUpdateSelected(BaseEventData eventData)
    {
        onUpdateselect?.Invoke(gameObject, eventData);
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="eventData"></param>
    public void OnSubmit(BaseEventData eventData)
    {
        onSumit?.Invoke(gameObject, eventData);
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="eventData"></param>
    public void OnCancel(BaseEventData eventData)
    {
        onCancel?.Invoke(gameObject, eventData);
    }
}

/// <summary>
/// 触发接听器扩展方法
/// </summary>
public static class EventTriggerListenerExpand
{
    #region Add方法
    /// <summary>
    /// 点击
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    /// <param name="mouseInput"></param>
    public static void AddClick(this GameObject go, EventTriggerListener.VoidDelegate function, PointerEventData.InputButton mouseInput = PointerEventData.InputButton.Left)
    {
        switch (mouseInput)
        {
            case PointerEventData.InputButton.Left:
                EventTriggerListener.Get(go).onClickLeft += function;
                break;
            case PointerEventData.InputButton.Right:
                EventTriggerListener.Get(go).onClickRight += function;
                break;
            case PointerEventData.InputButton.Middle:
                EventTriggerListener.Get(go).onClickMiddle += function;
                break;
            default:
                break;
        }
    }
    /// <summary>
    /// 双击
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    /// <param name="mouseInput"></param>
    public static void AddDoubleClick(this GameObject go, EventTriggerListener.VoidDelegate function, PointerEventData.InputButton mouseInput = PointerEventData.InputButton.Left)
    {
        switch (mouseInput)
        {
            case PointerEventData.InputButton.Left:
                EventTriggerListener.Get(go).onDoubleClickLeft += function;
                break;
            case PointerEventData.InputButton.Right:
                EventTriggerListener.Get(go).onDoubleClickRight += function;
                break;
            case PointerEventData.InputButton.Middle:
                EventTriggerListener.Get(go).onDoubleClickMiddle += function;
                break;
            default:
                break;
        }
    }
    /// <summary>
    /// 弹起
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    /// <param name="mouseInput"></param>
    public static void AddUp(this GameObject go, EventTriggerListener.VoidDelegate function, PointerEventData.InputButton mouseInput = PointerEventData.InputButton.Left)
    {
        switch (mouseInput)
        {
            case PointerEventData.InputButton.Left:
                EventTriggerListener.Get(go).onUpLeft += function;
                break;
            case PointerEventData.InputButton.Right:
                EventTriggerListener.Get(go).onUpRight += function;
                break;
            case PointerEventData.InputButton.Middle:
                EventTriggerListener.Get(go).onUpMiddle += function;
                break;
            default:
                break;
        }
    }
    /// <summary>
    /// 按下
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    /// <param name="mouseInput"></param>
    public static void AddDown(this GameObject go, EventTriggerListener.VoidDelegate function, PointerEventData.InputButton mouseInput = PointerEventData.InputButton.Left)
    {
        switch (mouseInput)
        {
            case PointerEventData.InputButton.Left:
                EventTriggerListener.Get(go).onDownLeft += function;
                break;
            case PointerEventData.InputButton.Right:
                EventTriggerListener.Get(go).onDownRight += function;
                break;
            case PointerEventData.InputButton.Middle:
                EventTriggerListener.Get(go).onDownMiddle += function;
                break;
            default:
                break;
        }
    }
    /// <summary>
    /// 按住
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    /// <param name="mouseInput"></param>
    public static void AddPress(this GameObject go, EventTriggerListener.VoidDelegate<float> function, PointerEventData.InputButton mouseInput = PointerEventData.InputButton.Left)
    {
        switch (mouseInput)
        {
            case PointerEventData.InputButton.Left:
                EventTriggerListener.Get(go).onPressLeft += function;
                break;
            case PointerEventData.InputButton.Right:
                EventTriggerListener.Get(go).onPressRight += function;
                break;
            case PointerEventData.InputButton.Middle:
                EventTriggerListener.Get(go).onPressMiddle += function;
                break;
            default:
                break;
        }
    }
    /// <summary>
    /// 鼠标浮上（Update）
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    public static void AddHover(this GameObject go, EventTriggerListener.VoidDelegate function)
    {
        EventTriggerListener.Get(go).onHover += function;
    }
    /// <summary>
    /// 鼠标不浮上（Update）
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    public static void AddLeave(this GameObject go, EventTriggerListener.VoidDelegate function)
    {
        EventTriggerListener.Get(go).onLeave += function;
    }
    /// <summary>
    /// 鼠标进入
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    public static void AddEnter(this GameObject go, EventTriggerListener.VoidDelegate function)
    {
        EventTriggerListener.Get(go).onEnter += function;
    }
    /// <summary>
    /// 鼠标离开
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    public static void AddExit(this GameObject go, EventTriggerListener.VoidDelegate function)
    {
        EventTriggerListener.Get(go).onExit += function;
    }
    /// <summary>
    /// 开始拖拽
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    /// <param name="mouseInput"></param>
    public static void AddBeginDrag(this GameObject go, EventTriggerListener.VoidDelegate function, PointerEventData.InputButton mouseInput = PointerEventData.InputButton.Left)
    {
        switch (mouseInput)
        {
            case PointerEventData.InputButton.Left:
                EventTriggerListener.Get(go).onBeginDragLeft += function;
                break;
            case PointerEventData.InputButton.Right:
                EventTriggerListener.Get(go).onBeginDragRight += function;
                break;
            case PointerEventData.InputButton.Middle:
                EventTriggerListener.Get(go).onBeginDragMiddle += function;
                break;
            default:
                break;
        }
    }
    /// <summary>
    /// 结束拖拽
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    /// <param name="mouseInput"></param>
    public static void AddEndDrag(this GameObject go, EventTriggerListener.VoidDelegate function, PointerEventData.InputButton mouseInput = PointerEventData.InputButton.Left)
    {
        switch (mouseInput)
        {
            case PointerEventData.InputButton.Left:
                EventTriggerListener.Get(go).onEndDragLeft += function;
                break;
            case PointerEventData.InputButton.Right:
                EventTriggerListener.Get(go).onEndDragRight += function;
                break;
            case PointerEventData.InputButton.Middle:
                EventTriggerListener.Get(go).onEndDragMiddle += function;
                break;
            default:
                break;
        }
    }
    /// <summary>
    /// 拖拽
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    /// <param name="mouseInput"></param>
    public static void AddDrag(this GameObject go, EventTriggerListener.VoidDelegate function, PointerEventData.InputButton mouseInput = PointerEventData.InputButton.Left)
    {
        switch (mouseInput)
        {
            case PointerEventData.InputButton.Left:
                EventTriggerListener.Get(go).onDragLeft += function;
                break;
            case PointerEventData.InputButton.Right:
                EventTriggerListener.Get(go).onDragRight += function;
                break;
            case PointerEventData.InputButton.Middle:
                EventTriggerListener.Get(go).onDragMiddle += function;
                break;
            default:
                break;
        }
    }
    /// <summary>
    /// 中键在物体上滑动
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    public static void AddScroll(this GameObject go, EventTriggerListener.VoidDelegate function)
    {
        EventTriggerListener.Get(go).onScroll += function;
    }
    /// <summary>
    /// 拖拽另一个物体松开在本体上
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    public static void AddDrop(this GameObject go, EventTriggerListener.VoidDelegate function)
    {
        EventTriggerListener.Get(go).onDrop += function;
    }
    /// <summary>
    /// 当物体被选中且键盘使用移动键时
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    public static void AddMove(this GameObject go, EventTriggerListener.VoidDelegate function)
    {
        EventTriggerListener.Get(go).onMove += function;
    }
    /// <summary>
    /// 当物体被选择时
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    public static void AddSelect(this GameObject go, EventTriggerListener.VoidDelegate function)
    {
        EventTriggerListener.Get(go).onSelect += function;
    }
    /// <summary>
    /// 当物体不被选择时
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    public static void AddDeselect(this GameObject go, EventTriggerListener.VoidDelegate function)
    {
        EventTriggerListener.Get(go).onDeselect += function;
    }
    /// <summary>
    /// 当物体被选择（每帧）
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    public static void AddUpdateselect(this GameObject go, EventTriggerListener.VoidDelegate function)
    {
        EventTriggerListener.Get(go).onUpdateselect += function;
    }
    /// <summary>
    /// 当物体被选择时键盘提交
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    public static void AddSumit(this GameObject go, EventTriggerListener.VoidDelegate function)
    {
        EventTriggerListener.Get(go).onSumit += function;
    }
    /// <summary>
    /// 当物体被选择时键盘取消
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    public static void AddCancel(this GameObject go, EventTriggerListener.VoidDelegate function)
    {
        EventTriggerListener.Get(go).onCancel += function;
    }

    #endregion

    #region Set方法

    /// <summary>
    /// 点击
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    /// <param name="mouseInput"></param>
    public static void SetClick(this GameObject go, EventTriggerListener.VoidDelegate function, PointerEventData.InputButton mouseInput = PointerEventData.InputButton.Left)
    {
        switch (mouseInput)
        {
            case PointerEventData.InputButton.Left:
                EventTriggerListener.Get(go).onClickLeft = function;
                break;
            case PointerEventData.InputButton.Right:
                EventTriggerListener.Get(go).onClickRight = function;
                break;
            case PointerEventData.InputButton.Middle:
                EventTriggerListener.Get(go).onClickMiddle = function;
                break;
            default:
                break;
        }
    }
    /// <summary>
    /// 双击
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    /// <param name="mouseInput"></param>
    public static void SetDoubleClick(this GameObject go, EventTriggerListener.VoidDelegate function, PointerEventData.InputButton mouseInput = PointerEventData.InputButton.Left)
    {
        switch (mouseInput)
        {
            case PointerEventData.InputButton.Left:
                EventTriggerListener.Get(go).onDoubleClickLeft = function;
                break;
            case PointerEventData.InputButton.Right:
                EventTriggerListener.Get(go).onDoubleClickRight = function;
                break;
            case PointerEventData.InputButton.Middle:
                EventTriggerListener.Get(go).onDoubleClickMiddle = function;
                break;
            default:
                break;
        }
    }
    /// <summary>
    /// 抬起
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    /// <param name="mouseInput"></param>
    public static void SetUp(this GameObject go, EventTriggerListener.VoidDelegate function, PointerEventData.InputButton mouseInput = PointerEventData.InputButton.Left)
    {
        switch (mouseInput)
        {
            case PointerEventData.InputButton.Left:
                EventTriggerListener.Get(go).onUpLeft = function;
                break;
            case PointerEventData.InputButton.Right:
                EventTriggerListener.Get(go).onUpRight = function;
                break;
            case PointerEventData.InputButton.Middle:
                EventTriggerListener.Get(go).onUpMiddle = function;
                break;
            default:
                break;
        }
    }
    /// <summary>
    /// 按下
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    /// <param name="mouseInput"></param>
    public static void SetDown(this GameObject go, EventTriggerListener.VoidDelegate function, PointerEventData.InputButton mouseInput = PointerEventData.InputButton.Left)
    {
        switch (mouseInput)
        {
            case PointerEventData.InputButton.Left:
                EventTriggerListener.Get(go).onDownLeft = function;
                break;
            case PointerEventData.InputButton.Right:
                EventTriggerListener.Get(go).onDownRight = function;
                break;
            case PointerEventData.InputButton.Middle:
                EventTriggerListener.Get(go).onDownMiddle = function;
                break;
            default:
                break;
        }
    }
    /// <summary>
    /// 按住
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    /// <param name="mouseInput"></param>
    public static void SetPress(this GameObject go, EventTriggerListener.VoidDelegate<float> function, PointerEventData.InputButton mouseInput = PointerEventData.InputButton.Left)
    {
        switch (mouseInput)
        {
            case PointerEventData.InputButton.Left:
                EventTriggerListener.Get(go).onPressLeft = function;
                break;
            case PointerEventData.InputButton.Right:
                EventTriggerListener.Get(go).onPressRight = function;
                break;
            case PointerEventData.InputButton.Middle:
                EventTriggerListener.Get(go).onPressMiddle = function;
                break;
            default:
                break;
        }
    }
    /// <summary>
    /// 鼠标浮上（每帧）
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    public static void SetHover(this GameObject go, EventTriggerListener.VoidDelegate function)
    {
        EventTriggerListener.Get(go).onHover = function;
    }
    /// <summary>
    /// 鼠标不浮上（每帧）
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    public static void SetLeave(this GameObject go, EventTriggerListener.VoidDelegate function)
    {
        EventTriggerListener.Get(go).onLeave = function;
    }
    /// <summary>
    /// 鼠标进入
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    public static void SetEnter(this GameObject go, EventTriggerListener.VoidDelegate function)
    {
        EventTriggerListener.Get(go).onEnter = function;
    }
    /// <summary>
    /// 鼠标离开
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    public static void SetExit(this GameObject go, EventTriggerListener.VoidDelegate function)
    {
        EventTriggerListener.Get(go).onExit = function;
    }
    /// <summary>
    /// 鼠标开始拖拽
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    /// <param name="mouseInput"></param>
    public static void SetBeginDrag(this GameObject go, EventTriggerListener.VoidDelegate function, PointerEventData.InputButton mouseInput = PointerEventData.InputButton.Left)
    {
        switch (mouseInput)
        {
            case PointerEventData.InputButton.Left:
                EventTriggerListener.Get(go).onBeginDragLeft = function;
                break;
            case PointerEventData.InputButton.Right:
                EventTriggerListener.Get(go).onBeginDragRight = function;
                break;
            case PointerEventData.InputButton.Middle:
                EventTriggerListener.Get(go).onBeginDragMiddle = function;
                break;
            default:
                break;
        }
    }
    /// <summary>
    /// 结束拖拽
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    /// <param name="mouseInput"></param>
    public static void SetEndDrag(this GameObject go, EventTriggerListener.VoidDelegate function, PointerEventData.InputButton mouseInput = PointerEventData.InputButton.Left)
    {
        switch (mouseInput)
        {
            case PointerEventData.InputButton.Left:
                EventTriggerListener.Get(go).onEndDragLeft = function;
                break;
            case PointerEventData.InputButton.Right:
                EventTriggerListener.Get(go).onEndDragRight = function;
                break;
            case PointerEventData.InputButton.Middle:
                EventTriggerListener.Get(go).onEndDragMiddle = function;
                break;
            default:
                break;
        }
    }
    /// <summary>
    /// 正在拖拽
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    /// <param name="mouseInput"></param>
    public static void SetDrag(this GameObject go, EventTriggerListener.VoidDelegate function, PointerEventData.InputButton mouseInput = PointerEventData.InputButton.Left)
    {
        switch (mouseInput)
        {
            case PointerEventData.InputButton.Left:
                EventTriggerListener.Get(go).onDragLeft = function;
                break;
            case PointerEventData.InputButton.Right:
                EventTriggerListener.Get(go).onDragRight = function;
                break;
            case PointerEventData.InputButton.Middle:
                EventTriggerListener.Get(go).onDragMiddle = function;
                break;
            default:
                break;
        }
    }
    /// <summary>
    /// 鼠标中键在该物体上滑动
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    public static void SetScroll(this GameObject go, EventTriggerListener.VoidDelegate function)
    {
        EventTriggerListener.Get(go).onScroll = function;
    }
    /// <summary>
    /// 拖拽另一个物体松开在本体上
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    public static void SetDrop(this GameObject go, EventTriggerListener.VoidDelegate function)
    {
        EventTriggerListener.Get(go).onDrop = function;
    }
    /// <summary>
    /// 当物体被选中且键盘使用移动键时
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    public static void SetMove(this GameObject go, EventTriggerListener.VoidDelegate function)
    {
        EventTriggerListener.Get(go).onMove = function;
    }
    /// <summary>
    /// 当物体被选择时
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    public static void SetSelect(this GameObject go, EventTriggerListener.VoidDelegate function)
    {
        EventTriggerListener.Get(go).onSelect = function;
    }
    /// <summary>
    /// 当物体不被选择时
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    public static void SetDeselect(this GameObject go, EventTriggerListener.VoidDelegate function)
    {
        EventTriggerListener.Get(go).onDeselect = function;
    }
    /// <summary>
    /// 当物体被选择（每帧）
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    public static void SetUpdateselect(this GameObject go, EventTriggerListener.VoidDelegate function)
    {
        EventTriggerListener.Get(go).onUpdateselect = function;
    }
    /// <summary>
    /// 当物体被选择时键盘提交
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    public static void SetSumit(this GameObject go, EventTriggerListener.VoidDelegate function)
    {
        EventTriggerListener.Get(go).onSumit = function;
    }
    /// <summary>
    /// 当物体被选择时键盘取消
    /// </summary>
    /// <param name="go"></param>
    /// <param name="function"></param>
    public static void SetCancel(this GameObject go, EventTriggerListener.VoidDelegate function)
    {
        EventTriggerListener.Get(go).onCancel = function;
    }
    #endregion
}
